local Class = require('lua.lang.Class')
local IntPointer = require('lua.vm.compiler.IntPointer')
local Constants = require('lua.vm.compiler.Constants')
local ExpressionValue = require('lua.vm.compiler.ExpressionValue')

--- @class ExpressionDescriptor : Class
--- @field expressionType number
--- @field expValue ExpressionValue
--- @field trueJumpTarget IntPointer
--- @field falseJumpTarget IntPointer
local ExpressionDescriptor = Class {}

--- @constructor
--- @return ExpressionDescriptor
function ExpressionDescriptor:new()
	--- @type ExpressionDescriptor
	local o = {}
	o.expressionType = 0
	o.expValue = ExpressionValue:new()
	o.trueJumpTarget = IntPointer:new()
	o.falseJumpTarget = IntPointer:new()
	return setmetatable(o, ExpressionDescriptor)
end

--- @param k number
--- @param i number
--- @return void
function ExpressionDescriptor:initialize(k, i)
	self.falseJumpTarget.i = Constants.NO_JUMP
	self.trueJumpTarget.i = Constants.NO_JUMP
	self.expressionType = k
	self.expValue.opcodeInfo = i
end

--- @return boolean
function ExpressionDescriptor:hasJumps()
	return self.trueJumpTarget.i ~= self.falseJumpTarget.i
end

--- @return boolean
function ExpressionDescriptor:isNumeral()
	return self.expressionType == Constants.VKNUM and self.trueJumpTarget.i == Constants.NO_JUMP and self.falseJumpTarget.i == Constants.NO_JUMP
end

--- @param other ExpressionDescriptor
--- @return void
function ExpressionDescriptor:setValue(other)
	self.falseJumpTarget.i = other.falseJumpTarget.i
	self.expressionType = other.expressionType
	self.trueJumpTarget.i = other.trueJumpTarget.i
	self.expValue.numericValue = other.expValue.numericValue
	self.expValue.rkIdx = other.expValue.rkIdx
	self.expValue.tIdx = other.expValue.tIdx
	self.expValue.valueTypeIndex = other.expValue.valueTypeIndex
	self.expValue.opcodeInfo = other.expValue.opcodeInfo
end

return ExpressionDescriptor